<?php

namespace App\Admin\Renderables;

use App\Admin\Actions\Delete;
use App\Logics\Logic;
use App\Models\AdminUser;
use App\Models\DyBaseInfo;
use App\Models\DyXfzdy;
use App\Models\DzzYjdzzInfo;
use App\Models\Role;
use App\Models\SpecialNode;
use App\Models\User;
use App\Policies\Admin\AdminPolicy;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
use Dcat\Admin\Widgets\Tooltip;

class DzzYjdzzInfoRenderTable extends LazyRenderable
{
    public function grid(): Grid
    {
        $admin_user = AdminUser::find(Admin::user()->id);
        $sql = isset($this->payload['sql']) ? $this->payload['sql'] : '';
        $builder = Logic::getBaseQuery(DzzYjdzzInfo::query(), $admin_user, false);
        if($sql){
            $builder->whereRaw($sql);
        }

        $grid = Grid::make($builder, function (Grid $grid) {
            $grid->column('dzzmc')->display(function($v) {
                if ($this->is_error) {
                    Tooltip::make('.bs-'.$this->id)->title(implode("<br/>", json_decode($this->errors, true)))->background('#ea5455')->maxWidth(600);
                    return '<span style="color:#304ffe; cursor: pointer" class="text-danger bs-'.$this->id.'">'.$v.'</span>';
                } else {
                    return $v;
                }
            });
            $grid->combine('党总支书记信息', ['sj_name', 'sj_sex', 'sj_mz', 'sj_gzgw', 'sj_xlxw', 'sj_zwzc'])->style('text-align: center;');
            $grid->column('ssdzzmc', '院级党组织所属党总支名称');
            $grid->column('qssj', '本届起始时间');
            $grid->column('rs', '总支部委员会人数');
            $grid->column('ndkhjg', '年度考核结果');
            $grid->column('sj_name', '姓名');
            $grid->column('sj_sex', '性别');
            $grid->column('sj_mz', '民族');
            $grid->column('sj_gzgw', '工作岗位');
            $grid->column('sj_xlxw', '学历学位');
            $grid->column('sj_zwzc', '职务职称');
            $grid->disableActions();
            $grid->setDialogFormDimensions('700px', '750px');
            $grid->disableCreateButton();
        });
        $grid->disableActions()->disableFilter()->disableCreateButton()->disableRowSelector();
        $grid->paginate(10);
        return $grid;
    }
}